package com.wffz.controller;

import com.wffz.comm.api.ResponseResult;
import com.wffz.po.ClientUser;
import com.wffz.po.UserNotice;
import com.wffz.service.NoticeService;
import com.wffz.service.UserNoticeService;
import com.wffz.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Date;

/**
 * @Description: [公告信息]
 * @Title:
 * @Author: SUNLEI
 * @Date: 2023-03-20
 * @Param: null
 * @Return: null
 * @Throws:
 */
@RequestMapping("/notice")
@RestController
@Slf4j
public class NoticeController {


    @Resource
    private UserNoticeService userNoticeService;

    @Resource
    private NoticeService service;


    @Resource
    private UserService userService;

    @GetMapping("/queryNotice")
    public ResponseResult queryNotice(HttpServletRequest request) {
        Principal principal = request.getUserPrincipal();
        ClientUser clientUser = userService.findUserByUserName(principal.getName());
        return ResponseResult.success(service.queryNotice(clientUser.getId()));
    }

    @PostMapping("saveUserNotice")
    public ResponseResult saveUserNotice(HttpServletRequest request,@RequestParam String noticeId) {
        Principal principal = request.getUserPrincipal();
        ClientUser clientUser = userService.findUserByUserName(principal.getName());
        UserNotice userNotice = new UserNotice();
        userNotice.setUserId(clientUser.getId());
        userNotice.setLoginName(clientUser.getLoginName());
        userNotice.setNoticeId(Long.parseLong(noticeId));
        userNotice.setCreateTime(new Date());
        return ResponseResult.success(userNoticeService.saveUserNotice(userNotice));
    }

}
